package com.kadron.item;

import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.kadron.dao.KPriceDAO;
import com.kadron.entity.Currency;
import com.kadron.entity.Item;
import com.kadron.entity.Price;

public class KItemPrices implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1758506057861413584L;
	
	private Map<Currency,KPriceData> priceMap = new HashMap<Currency, KPriceData>();

	public KItemPrices(Item item, KPriceDAO priceDAO) {
		List<Currency> currencies = priceDAO.getAll(Currency.class);
		List<Price> prices = priceDAO.getPrices(item.getId());
		for (Price p : prices) {
			Currency c = p.getCurrency();
			if (!priceMap.containsKey(c)) {
				priceMap.put(c, new KPriceData(c.getId(), p.getPrice()));
			}
		}
		for (Currency c : currencies) {
			if (!priceMap.containsKey(c)) {
				priceMap.put(c, new KPriceData(c.getId()));
			}
		}
	}

	public Map<Currency, KPriceData> getPriceMap() {
		return priceMap;
	}
	
	public List<Currency> getKeys() {
		List<Currency> keys = new LinkedList<Currency>(priceMap.keySet());
		return keys;
	}
	
	public KPriceData get(Currency currency) {
		if (currency == null) {
			return null;
		}
		return priceMap.get(currency);
	}
	
}
